package com.typy.www.tpay.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.typy.www.tpay.bean.vm.ActivicationVm;
import com.typy.www.tpay.bean.vm.BuyVm;
import com.typy.www.tpay.bean.vm.IcoTypeVm;
import com.typy.www.tpay.ui.itemview.DigiBuyItem;
import com.typy.www.tpay.ui.itemview.IcoItemView;
import com.typy.www.tpay.ui.itemview.IcotypeItemView;
import com.typy.www.tpay.ui.itemview.NoticeItemView;
import com.typy.www.tpay.ui.itemview.RecordActivicationItemView;
import com.typy.www.tpay.ui.itemview.RecordItemView;
import com.typy.www.tpay.util.ClassHoldUtil;

import java.util.List;

/**
 * Created by 13799 on 2018/7/10.
 */

public class IcotypeAdapter extends BaseAdapter {
    private List<IcoTypeVm> data;
    private List<BuyVm> buyData;
    private Context mContext;
    private int classType;
    private boolean isBuy;
    private String fdSeqNo;
    private String fdName;

    public void setIsBuy(boolean isBuy) {
        this.isBuy = isBuy;
    }

    public void setmType(int classType) {
        this.classType = classType;
    }

    public void setFdName(String fdName,String fdSeqNo) {
        this.fdName = fdName;
        this.fdSeqNo = fdSeqNo;
    }

    public IcotypeAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<IcoTypeVm> data) {
        this.data = data;
    }

    public void setBuyData(List<BuyVm> buyData) {
        this.buyData = buyData;
    }

    @Override
    public int getCount() {
        if (classType == ClassHoldUtil.DigitalAssets||classType==ClassHoldUtil.ICOYURE||classType==ClassHoldUtil.ICOJINXING||classType==ClassHoldUtil.ICOJIESU)
            return data == null ? 0 : data.size();
        else
            return buyData == null ? 0 : buyData.size();
    }

    @Override
    public Object getItem(int position) {
        if (classType == ClassHoldUtil.DigitalAssets||classType==ClassHoldUtil.ICOYURE||classType==ClassHoldUtil.ICOJINXING||classType==ClassHoldUtil.ICOJIESU)
            return data.get(position);
        else
            return buyData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (classType == ClassHoldUtil.DigitalAssets) {
            IcotypeItemView itemView = null;
            if (convertView == null) {
                itemView = new IcotypeItemView(mContext);
                convertView = itemView.getView();
                convertView.setTag(itemView);
            } else {
                itemView = (IcotypeItemView) convertView.getTag();
            }
            itemView.bind(data.get(position), position, classType);
        }  else if (classType==ClassHoldUtil.ICOYURE||classType==ClassHoldUtil.ICOJINXING||classType==ClassHoldUtil.ICOJIESU) {
            IcoItemView itemView = null;
            if (convertView == null) {
                itemView = new IcoItemView(mContext);
                convertView = itemView.getView();
                convertView.setTag(itemView);
            } else {
                itemView = (IcoItemView) convertView.getTag();
            }
            itemView.bind(data.get(position), position, classType);
        } else {
            DigiBuyItem itemView = null;
            if (convertView == null) {
                itemView = new DigiBuyItem(mContext);
                convertView = itemView.getView();
                convertView.setTag(itemView);
            } else {
                itemView = (DigiBuyItem) convertView.getTag();
            }
            itemView.bind(buyData.get(position),position,isBuy,fdName,fdSeqNo);
        }
        return convertView;
    }
}
